// 获取cookie中的用户名
function getname (){
   var username = getCookie('username')  
  if(username){
   $('.login-rge')[0].outerHTML= `
   <li  class="login-rge">
       <a  href="usercenter.html"><span>${username}</span></a>
       <a class = "del" onclick = outlogin()>退出</a>
   </li>
       `
  }
}  

// 页面资源加载完成后才显示网页
function windowloads(){
    document.onreadystatechange = function () {
        if (document.readyState == "complete") {
            document.body.style.display = "block";
        } else {
            document.body.style.display = "none";
        };
    };

}

// 点击退出按钮
function outloginfn(){
layer.confirm('你确定要退出吗？',{
    btn:['退出','取消']      
    },function(){
        removeCookie('username')
        $('.login-rge')[0].outerHTML = `
        <li  class="login-rge">
        <a href="login.html">欢迎登录名鞋库</a> <a href="register.html">免费注册</a> 
        </li>
            `
        location.reload();
        removeCookie('username')
        removeCookie('userid')
        removeCookie('captcha')
        localStorage.removeItem('token')
    })
}

// 禁止选中网页中的文字
function prohibit(){  
document.onselectstart = function() {return false};
document.unselectable = 'on'; 
}

// 获取头像
function getheadmig(){
$.ajax({
    type: 'get',
    url: '/users/api/list/'+userid,
    headers: {
        'Authorization': localStorage.getItem('token')
    },
    success: res=> {
        if(res.data.userInfo.url){
            $('.userlog img')[0].src = res.data.userInfo.url
        }else{
            $('.userlog img')[0].src = 'f790b51a76afd7b41522048fa779d69d.jpg'
        }
    }
    })
}

// 获取购物车中的商品种类
function getspumber(){
    let userid = getCookie('userid')
    $.ajax({
        type: 'get',
        url: '/cart/api/list/'+userid,
        headers: {
            'Authorization': localStorage.getItem('token')
        },
        success: res=> {

        if(res.data){
            $('.Shopping i')[0].innerText =  res.data.length
            setStyle($('.Shopping i')[0],{
                color:'#fff',
                background:'#de3a3a',
                'border-radius':'50%',
                height:'15px',
                width:'15px',
                padding:'0px 5px 0px 5px',
                font:'800 14px/0px ""',
            })
        }
        }
        })
}